/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mx.itsc.ds2.Dao;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import mx.itsc.ds2.model.Scholarship;

/**
 *
 * @author Juan Carlos
 */
@Stateless
public class ScholarshipDao extends AbstractDao<Scholarship> implements ScholarshipDaoLocal {
    @PersistenceContext(unitName = "MusicSchoolStudentControl-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public ScholarshipDao() {
        super(Scholarship.class);
    }

    @Override
    public Boolean findDuplicity(Scholarship scholarship) {
        Query q = em.createNamedQuery("Scholarship.findDuplicity");
        q.setParameter("id", scholarship.getId());
        q.setParameter("scholarshipTipe", scholarship.getScholarshipTipe());
        return !q.getResultList().isEmpty();
    }

    @Override
    public List<Scholarship> findByScholarship(Scholarship scholarship) {
        Query q = em.createNamedQuery("Scholarship.findByScholarshipTipe");
        q.setParameter("scholarshipTipe", scholarship.getScholarshipTipe());
        return q.getResultList();
    }
    
    
    
}
